<?php
/**
 * Created by PhpStorm.
 * User: jocky
 * Date: 31/08/2017
 * Time: 22:29
 */
namespace frontend\controllers;

class LogoutController extends FrontendController
{
    public function actionIndex()
    {
        if (!\Yii::$app->user->isGuest) {
            \Yii::$app->user->logout();
        }

        if (\Yii::$app->request->isAjax) {
            exit(json_encode(['code' => 1, 'msg' => 'ok']));
        } else {
            $this->redirect('/');
        }
    }
}